<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑版权</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/common.css" media="all">
    <link rel="stylesheet" href="../viewstyle/css/searchform.css">
    <script src="/js/layui/layui.all.js"></script>
    <script src="/admin/js/token.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body" pad15>
                    <form class="layui-form" lay-filter="selFilter">
                        <div class="layui-form-item">
                            <lable class="layui-form-label">版权名称:</lable>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input"
                                       style="width: 30%" id="typename" >
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <lable class="layui-form-label">图片:</lable>
                            <div class="layui-input-block">
                                <img src="" id="myimg" style="width: 80px;height: 80px;" />
                                <p style="color: red">*点击图片框上传图片</p>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">状态:</label>
                            <div class="layui-input-block" style="width: 30%">
                                <select name="type" lay-verify="required" id="status">
                                    <option value="禁用">禁用</option>
                                    <option value="启用">启用</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn  layui-icon layui-icon-survey" lay-submit=""
                                        id="update" lay-filter="update">
                                    修改
                                </button>
                                <button class="layui-btn  layui-icon layui-icon-close" id="back">
                                    取消
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
        var form = layui.form;
        var upload = layui.upload;
        var $ = layui.$;
        var data=layui.data("banquan").getdata;
        $("#typename").val(data.copyrighttype);
        $("#myimg").attr("src","http://127.0.0.1:8080/upload/"+data.copyrightpicture);
        $("#status").val(data.copyrightstatus);
        var banquanid=data.copyrightid;
        var filename='';
        form.render('select', 'selFilter');
        //修改的监听事件
        form.on('submit(update)', function () {
            $.ajax({
                url: "/admin/copyright/editCopyRight",
                type: "post",
                data: {
                    copyrightid: banquanid,
                    copyrighttype: $("#typename").val(),
                    copyrightstatus: $("#status").val(),
                    copyrightpicture:filename
                },
                success: function (res) {
                    if (res.code == 200) {
                        layer.msg("修改成功", {
                            icon: 1
                        });
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);    //关闭弹出层
                        }, 2000)
                    } else if (res.code == 400) {
                        layer.msg(res.data, {
                            icon: 2
                        })
                    } else {
                        layer.msg("修改失败", {
                            icon: 2
                        })
                    }
                },
                error: function () {
                    layer.msg("系统原因修改失败", {
                        icon: 2
                    })
                }
            })
            return false;
        });
        upload.render({
            elem:"#myimg",
            url:"/admin/fileinfo/upload/image",
            choose: function(obj) {
                filename = null;
                //预览
                obj.preview(function(index, file, result) {
                    $("#myimg").attr('src', result);
                });
            },
            done: function(res, index, upload) //上传完成
            {
                filename = res.data; //传回来的新的文件名
            }
        })
        $('#back').click(function () {
            var index = parent.layer.getFrameIndex(window.name) //获取窗口索引
            parent.layer.close(index)    //关闭弹出层
        })
</script>
</body>
</html>